// Copyright 2022 jeff.li. and/or its affiliates.

#pragma once

#include <cstdint>

namespace tbir::runtime {

    class EnvTime {
    public:
        static constexpr uint64_t kMicrosToPicos = 1000ULL * 1000ULL;
        static constexpr uint64_t kMicrosToNanos = 1000ULL;
        static constexpr uint64_t kMillisToMicros = 1000ULL;
        static constexpr uint64_t kMillisToNanos = 1000ULL * 1000ULL;
        static constexpr uint64_t kSecondsToMillis = 1000ULL;
        static constexpr uint64_t kSecondsToMicros = 1000ULL * 1000ULL;
        static constexpr uint64_t kSecondsToNanos = 1000ULL * 1000ULL * 1000ULL;

        EnvTime() = default;

        virtual ~EnvTime() = default;

        /// \brief Returns a default impl suitable for the current operating
        /// system.
        ///
        /// The result of Default() belongs to this library and must never be deleted.
        static EnvTime *Default();

        /// \brief Returns the number of nano-seconds since the Unix epoch.
        virtual uint64_t NowNanos() const = 0;

        /// \brief Returns the number of micro-seconds since the Unix epoch.
        virtual uint64_t NowMicros() const {
            return NowNanos() / kMicrosToNanos;
        }

        /// \brief Returns the number of seconds since the Unix epoch.
        virtual uint64_t NowSeconds() const {
            return NowNanos() / kSecondsToNanos;
        }
    };

}  // namespace tbir::runtime
